


import matplotlib.pyplot as plt
import numpy as np
import matplotlib.pyplot as plt

#设置默认字体
import pylab as mpl  # import matplotlib as mpl
mpl.rcParams['font.sans-serif'] = ['Microsoft YaHei']  # 指定默认字体

x = np.linspace(-3, 3, 50)
y1 = 2*x + 1
y2 = x**2

plt.figure()
# set x limits
plt.xlim((-1, 2))
plt.ylim((-2, 3))

# set new sticks
new_sticks = np.linspace(-1, 2, 5)
plt.xticks(new_sticks)
# set tick labels
plt.yticks([-2, -1.8, -1, 1.22, 3],
           [r'$really\ bad$', r'$bad$', r'$normal$', r'$good$', r'$really\ good$'])

#将创建的线赋值给l1 l2,注意赋值形式中的“，”
l1, = plt.plot(x, y1, label='up')
l2, = plt.plot(x, y2, color='red', linewidth=1.0, linestyle='--', label='down')

#设置图例
plt.legend(handles=[l1,l2],labels=["直线","抛物线"],loc='best')


plt.show()